import java.util.Map;
import java.util.Set;

import org.dom4j.Element;

import com.alibaba.fastjson.JSONObject;
import com.justep.ui.wx.WXComponentContext;
import com.justep.ui.wx.component.WXComponent;

public class WxPay extends WXComponent{
	public String getTagName(){
		return "view";
	}
	public JSONObject doExecute(Element bound, Map<String, Object> context, WXComponentContext wxContext) {
		JSONObject props = new JSONObject();	     
		String id = bound.attributeValue("id");
		String outTradeno = bound.attributeValue("outTradeno");
		bound.addAttribute("outTradeNo","");
		String shopName = bound.attributeValue("shopName");
		bound.addAttribute("shopName","");
		String productName = bound.attributeValue("productName");
		bound.addAttribute("productName","");
		String totalFee = bound.attributeValue("totalFee");
		bound.addAttribute("totalFee","");	
		String productId = bound.attributeValue("productId");
		bound.addAttribute("productId","");
		String limitPay = bound.attributeValue("limitPay");
		String openid = bound.attributeValue("openid");
		bound.addAttribute("openid","");

		props.put("outTradeno", outTradeno);
		processExprValue(outTradeno,props,id,"outTradeno",bound,context,wxContext);
		props.put("shopName", shopName);
		processExprValue(shopName,props,id,"shopName",bound,context,wxContext);
		props.put("productName", productName);
		processExprValue(productName,props,id,"productName",bound,context,wxContext);
		props.put("totalFee", totalFee);
		processExprValue(totalFee,props,id,"totalFee",bound,context,wxContext);
		props.put("productId", productId);
		processExprValue(productId,props,id,"productId",bound,context,wxContext);
		props.put("limitPay", limitPay);
		props.put("openid", openid);
		processExprValue(openid,props,id,"openid",bound,context,wxContext);
		
		return props;
	}

	protected void processExprValue(String expr, JSONObject props,String id,String name,Element bound, Map<String, Object> context,WXComponentContext wxContext){
		if(null==expr || "".equals(expr)) return;
		String paramsFn = "$exprBinding_" + id + "_" + name;
		props.put("$executeExprBinding" + "_" + name, paramsFn);
		Set<String> dataIds = getDataIds(bound, context);
		StringBuffer body = new StringBuffer("return " + expr);
		generateFn(paramsFn, body.toString(), wxContext, dataIds);
	}
}